package by2019;
/*
 * 这其实十分的简单
 */
public class 二叉树的中序遍历 {

	public static void main(String[] args) {
		//创建一颗二叉树，并给他赋值
		TreeNode[] node = new TreeNode[10];
		for(int i=0; i<10; i++) {
			node[i] = new TreeNode(i);
		}
		for(int i=0; i<10; i++) {
			if(i*2+1<10)
				node[i].left = node[i*2+1] ;
			if(i*2+2<10)
				node[i].right = node[i*2+2] ;
		}
		//对以0为顶点的这颗二叉树进行中序输出
		midOrder(node[0]);
		System.out.println();
	}
	
	//对传入的二叉树的左右子树分别进行中序输出，先输出左边子树，再输出顶点，再输出右边子树
	public static void midOrder(TreeNode tree) {
		if(tree==null) 
			return ;
		else {
			midOrder(tree.left );
			System.out.print(tree.val+"  ");
			midOrder(tree.right);
		}
	}

}



